﻿using System.Collections.Generic;
using System.Linq;

namespace Best.SmartCms.Dto.Response
{
    /// <summary>
    /// WebApi返回带分页实体数据类
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class PagedResponse<T> : ApiResponse, IPagedResponse
    {
        /// <inheritdoc cref="IPagedResponse"/>
        public int PageIndex { get; set; }

        /// <inheritdoc cref="IPagedResponse"/>
        public int PageSize { get; set; }

        /// <inheritdoc cref="IPagedResponse"/>
        public int TotalPages { get; set; }

        /// <inheritdoc cref="IPagedResponse"/>
        public int TotalCount { get; set; }

        /// <summary>
        /// 业务数据
        /// </summary>
        public List<T> Data { get; set; }

        /// <summary>
        /// Ctor
        /// </summary>
        public PagedResponse()
        {
            
        }


        /// <summary>
        /// 自动分页
        /// </summary>
        /// <param name="data"></param>
        /// <param name="pageIndex">页码 1-Index</param>
        /// <param name="pageSize">分页大小</param>
        /// <param name="totalCount"></param>
        /// <param name="totalPages"></param>
        public PagedResponse(List<T> data, int pageIndex, int pageSize, int totalCount, int totalPages)
        {
            Success = true;
            Code = ResponseCode.Success;
            Data = data;
            PageIndex = pageIndex;
            PageSize = pageSize;
            TotalCount = totalCount;
            TotalPages = totalPages;
            Success = true;
        }
        
    }
}